var status = -1;
var selectionLog = [];

function start() {
    action(1, 0, 0)
}

function action(j, k, l) {
    var e = im.getItemId();
    var b = im.getNumberFromQuestInfo(100488, "lv");
    var a = im.getNumberFromQuestInfo(100485, "use");
    var h = im.itemQuantity(e);
    var c = exp[b];
    var d = c - a;
    if (status == 0 && j == 0) {
        im.dispose();
        return
    }(j == 1) ? status++ : status--;
    selectionLog[status] = l;
    var g = -1;
    if (status <= g++) {
        im.dispose()
    } else {
        if (status === g++) {
            if (b >= 12) {
                im.sendOk("骨碌骨碌屋已经升到最高级啦！没法再继续升级了。", 9062276);
                im.dispose();
                return
            }
            var m = Math.min(h, d);
            im.askNumber("\r\n#b#e要听多少#t2631384:##n#k？\r\n直到骨碌骨碌屋 #b#eLv. " + (b + 1) + "#n#k 为止，还能再听 #r#e" + d + "个#n#k！\r\n\r\n - 当前骨碌骨碌屋等级：#r#eLv. " + b + "#n#k\r\n - 升级至下一等级所需的旋律数量：#b#e" + c + "#n#k\r\n - 目前为止所听的旋律数量： #b#e" + a + "#n#k\r\n", 9062276, m, 1, d, 0)
        } else {
            if (status === g++) {
                im.dispose();
                var m = Math.min(l, d);
                if (m > h) {
                    im.sendOk("#i" + e + ":# #t" + e + ":#数量不够呢！现在只有#b" + h + "#k个。");
                    return
                }
                im.addNumberForQuestInfo(100485, "use", m);
                im.getPlayer().getTopMsgByItem(2437958, "骨碌骨碌屋听着品克缤之旋律长大了。");
                im.effect_Voice("UI.img/productSuccess", 100);
                im.gainItem(e, -d);
                if (l < d) {
                    return
                }
                im.setNumberForQuestInfo(100485, "use", 0);
                var f = im.addNumberForQuestInfo(100488, "lv", 1);
                switch (f) {
                    case 2:
                        im.setNumberForQuestInfo(100488, "part0", 10);
                        im.setNumberForQuestInfo(100488, "part1", 10);
                        im.setNumberForQuestInfo(100488, "part2", 10);
                        im.setNumberForQuestInfo(100488, "part3", 10);
                        im.sendNormalTalk("骨碌骨碌屋成长到" + f + "级了！\r\n\r\n#e#b[ Lv." + f + " ]#n#k\r\n\r\n- 骨碌骨碌屋变得更大了。", 4, 9062276, 0, 1);
                        break;
                    case 3:
                        im.sendNormalTalk("骨碌骨碌屋成长到" + f + "级了！\r\n\r\n#e#b[ Lv." + f + " ]#n#k\r\n\r\n- 可进行骨碌骨碌屋#e#b墙壁的变更#n#。", 4, 9062276, 0, 1);
                        break;
                    case 4:
                        im.sendNormalTalk("骨碌骨碌屋成长到" + f + "级了！\r\n\r\n#e#b[ Lv." + f + " ]#n#k\r\n\r\n- 可进行骨碌骨碌屋#e#b尖角的变更#n#k。", 4, 9062276, 0, 1);
                        break;
                    case 5:
                        im.sendNormalTalk("骨碌骨碌屋成长到" + f + "级了！\r\n\r\n#e#b[ Lv." + f + " ]#n#k\r\n\r\n- 可进行骨碌骨碌屋#e#b脸颊的变更#n#k。", 4, 9062276, 0, 1);
                        break;
                    case 6:
                        im.setNumberForQuestInfo(100488, "part4", 0);
                        im.setNumberForQuestInfo(100488, "part5", 0);
                        im.setNumberForQuestInfo(100488, "part6", 0);
                        im.setNumberForQuestInfo(100488, "part7", 0);
                        im.setNumberForQuestInfo(100488, "part8", 0);
                        im.setNumberForQuestInfo(100488, "part9", 0);
                        im.addNumberForQuestInfo(100488, "part0", -10);
                        im.addNumberForQuestInfo(100488, "part1", -10);
                        im.addNumberForQuestInfo(100488, "part2", -10);
                        im.addNumberForQuestInfo(100488, "part3", -10);
                        im.sendNormalTalk("骨碌骨碌屋成长到" + f + "级了！\r\n\r\n#e#b[ Lv." + f + " ]#n#k\r\n\r\n- 骨碌骨碌屋变得更大了。\r\n\r\n- 可进行骨碌骨碌屋#e#b窗户的变更#n#k。", 4, 9062276, 0, 1);
                        break;
                    case 7:
                        im.sendNormalTalk("骨碌骨碌屋成长到" + f + "级了！\r\n\r\n#e#b[ Lv." + f + " ]#n#k\r\n\r\n- 可进行骨碌骨碌屋#e#b标记的变更#n#k。", 4, 9062276, 0, 1);
                        break;
                    case 8:
                        im.sendNormalTalk("骨碌骨碌屋成长到" + f + "级了！\r\n\r\n#e#b[ Lv." + f + " ]#n#k\r\n\r\n- 可进行骨碌骨碌屋#e#b品克缤玩具的变更#n#k。", 4, 9062276, 0, 1);
                        break;
                    case 9:
                        im.sendNormalTalk("骨碌骨碌屋成长到" + f + "级了！\r\n\r\n#e#b[ Lv." + f + " ]#n#k\r\n\r\n- 可进行骨碌骨碌屋#e#b房顶装饰的变更#n#k。", 4, 9062276, 0, 1);
                        break;
                    case 10:
                        im.sendNormalTalk("骨碌骨碌屋成长到" + f + "级了！\r\n\r\n#e#b[ Lv." + f + " ]#n#k\r\n\r\n- 可进行骨碌骨碌屋#e#b门的变更#n#k。", 4, 9062276, 0, 1);
                        break;
                    case 11:
                        im.sendNormalTalk("骨碌骨碌屋成长到" + f + "级了！\r\n\r\n#e#b[ Lv." + f + " ]#n#k\r\n\r\n- 可进行骨碌骨碌屋#e#b特效的变更#n#k。", 4, 9062276, 0, 1);
                        break;
                    case 12:
                        im.sendNormalTalk("骨碌骨碌屋成长到" + f + "级了！\r\n\r\n#e#b[ Lv." + f + " ]#n#k\r\n\r\n- 可进行骨碌骨碌屋#e#b共同座椅的变更#n#k。", 4, 9062276, 0, 1);
                        im.forceCompleteQuest(100484);
                        break
                }
            } else {
                if (status === g++) {
                    im.dispose()
                }
            }
        }
    }
}
var exp = [0, 100, 100, 200, 200, 200, 300, 300, 300, 400, 400, 500];